C Sharp
snippet | |
---|---|
string read_query = ""; int total_active = 0; int total_active_2 = 0; // populate dropdowns // ./. // assign varaible to connection string myConnection = "datasource=localhost;port=3306;username=root;password=''"; // conncet by varaible MySqlConnection myConn = new MySqlConnection(myConnection); // assign varaible to reading from data base MySqlDataReader mdr; // open connection List List List // command string string selectQuery1 = "show tables from methods"; myConn.Open(); // execute commadnt to select quary MySqlCommand SelectCommand = new MySqlCommand(selectQuery1, myConn); MySqlCommand command = new MySqlCommand(selectQuery1, myConn); // assign varaible to reader of fethcing quary mdr = SelectCommand.ExecuteReader(); // assign value feteched to text box while (mdr.Read()) { tables_list.Add(mdr.GetString("Tables_in_methods")); } // close connection myConn.Close(); // MessageBox.Show(tables_list[5]); for (int ii = 0; ii < tables_list.Count; ii++) { if (tables_list[ii] != "all_methods" && tables_list[ii] != "all_super_methods") { int total_rows = 0; // get total rows myConn.Open(); // command strings string systems_rows_count_query = "SELECT COUNT(*) FROM methods."+ tables_list[ii]+"; "; // execute commadnt to select quary SelectCommand = new MySqlCommand(systems_rows_count_query, myConn); // assign varaible to reader of fethcing quary mdr = SelectCommand.ExecuteReader(); // assign value feteched to text box if (mdr.Read()) { total_rows = Int32.Parse(mdr.GetString("COUNT(*)")); } // close connection myConn.Close(); methods_list.Clear(); dates_list.Clear(); // MessageBox.Show("not yet 1"); //MessageBox.Show(tables_list[ii]); for (int jj = 0; jj < total_rows; jj++) { myConn.Open(); try { // command strings //MessageBox.Show("SELECT method,date_created FROM methods." + tables_list[ii] + " where id =" + (jj + 1) + "; "); read_query = "SELECT method,date_created FROM methods." + tables_list[ii] + " where id =" + (jj + 1) + "; "; // execute commadnt to select quary SelectCommand = new MySqlCommand(read_query, myConn); // assign varaible to reader of fethcing quary mdr = SelectCommand.ExecuteReader(); // assign value feteched to text box if (mdr.Read()) { if (mdr.GetString("method") != "xxx") { methods_list.Add(mdr.GetString("method")); dates_list.Add(mdr.GetString("date_created")); } } } catch { } myConn.Close(); } // MessageBox.Show("not yet 3"); } //MessageBox.Show("not yet 4"); for (int kk = 0; kk < methods_list.Count; kk++) { myConn.Open(); string insertQuery = "INSERT INTO methods.all_methods (`id`, `method`, `date_created`,`table`) VALUES (NULL, '" + methods_list[kk] + "', '" + dates_list[kk] + "','" + tables_list[ii] + "');"; command = new MySqlCommand(insertQuery, myConn); if (tables_list[ii]!="all_methods"&& tables_list[ii] != "all_super_methods") { if (command.ExecuteNonQuery() == 1) { } else { MessageBox.Show("Data Not Inserted"); } } myConn.Close(); } } | |
List List list1.AddRange(list2); | |
// assign picture based on words in subdetails // ./. // get assigned images // ./. string assigned_image_1 = ""; // open connection myConn.Open(); // command string selectQuery1 = "SELECT sub_details_1_1_picture FROM memorization.chemistry_1 where id = " + current_id.ToString(); // execute commadnt to select quary SelectCommand = new MySqlCommand(selectQuery1, myConn); // assign varaible to reader of fethcing quary mdr = SelectCommand.ExecuteReader(); // assign value feteched to text box if (mdr.Read()) { assigned_image_1 = mdr.GetString("sub_details_1_1_picture"); } // close connection myConn.Close(); // /./ // add paragraphs to lists // ./. string[] detail_box_1_words = detail_box_1.Text.Split(' '); foreach (var word in detail_box_1_words) { paragraph_list_1.Add(word); } // /./ // shuffle lists // ./. var paragraph_list_1_shuffled = paragraph_list_1.OrderBy(a => Guid.NewGuid()).ToList(); // /./ // loop thought lists till match from images and update ot table. if no match choose image at random Random random = new Random(); int random_2 = 0; string[] images_array = Directory.GetFiles(@"C:Usersmr bigDropboxcodec sharp one snippetsstyleimages"); string match = "x"; if (paragraph_list_1_shuffled[0] != "xxx" && assigned_image_1 == "xxx") { for (ii = 0; ii < images_array.Length; ii++) { if (images_array[ii].Equals(Path.GetFileNameWithoutExtension(images_array[ii]), StringComparison.InvariantCultureIgnoreCase)) { pictureBox1.Image = Image.FromFile(images_array[ii]); match = "v"; ii = images_array.Length; insertQuery4 = "update memorization.chemistry_1 set sub_details_1_1_picture = '" + MySql.Data.MySqlClient.MySqlHelper.EscapeString(images_array[ii])+"' where id = "+ current_id.ToString(); // open ocnnection } } if (match == "x") { random_2 = random.Next(0, images_array.Length-1); pictureBox1.Image = Image.FromFile(images_array[random_2]); insertQuery4 = "update memorization.chemistry_1 set sub_details_1_1_picture = '" + MySql.Data.MySqlClient.MySqlHelper.EscapeString(images_array[random_2]) + "' where id = " + current_id.ToString(); } myConn.Open(); command = new MySqlCommand(insertQuery4, myConn); if (command.ExecuteNonQuery() == 1) { } else { MessageBox.Show("Data Not Inserted"); } // close connection myConn.Close(); // close if not xxx } if (assigned_image_1 != "xxx") { pictureBox1.Image = Image.FromFile(assigned_image_1); } // /./ | |
grid_1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; grid_1.AutoResizeColumns(); for (int i = 0; i < grid_1.Columns.Count - 1; i++) { if (grid_1.Columns[i].Width > 150) { grid_1.Columns[i].Width = 150; } } | |
detail_box_1.Text = detail_box_1.Text.ToLower(); | |
if (ii % 3 == 0){} | |
if (Path.GetFileNameWithoutExtension(images_array[ii]).StartsWith(search_box.Text)) { dropdown_1.Items.Add(new KeyValuePair dropdown_2.Items.Add(new KeyValuePair } | |
if ("abc3def".Any(char.IsDigit ) == true){MessageBox.Show("has number");} | |
string stringTest = "123"; if (stringTest.All(char.IsDigit) == true){ MessageBox.Show("a number"); } | |
class check_if_hour_passed { public static string check_if_hour_passed_function(int hour, int minute) { string returned_value = "not_passed"; DateTime now = DateTime.Now; int subtracted_day = now.Day; int subtracted_month = now.Month; int subtracted_year = now.Year; if (hour == now.Hour) { if (minute < now.Minute) { returned_value = "passed"; } } if (hour < now.Hour) { returned_value = "passed"; } return returned_value; } | |
DateTime today = DateTime.Today; DateTime lastDayOfMonth = new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month)); if (today == lastDayOfMonth) { Console.WriteLine("Today is the last day of the month."); } else { Console.WriteLine("Today is not the last day of the month."); } | |
public static bool check_if_time_is_within_range_function(double startTime, double endTime) { bool returned_value = false; DateTime currentTime = DateTime.Now; TimeSpan timeOfDay = currentTime.TimeOfDay; double totalMinutes = timeOfDay.TotalMinutes; //double startTime = 9 * 60; // 9:00 AM in minutes //double endTime = 17 * 60; // 5:00 PM in minutes if (totalMinutes >= startTime && totalMinutes <= endTime) { // The current time is within the range of 9:00 AM to 5:00 PM returned_value = true; } return returned_value; } | |
GC.Collect(); | |
int ii = 0; int open_connections = 0; string sql = " SELECT * FROM methods.sleep "; string myConnection = "datasource=localhost;port=3306;username=root;password='';Charset=utf8;maximumpoolsize=1000"; MySqlConnection myConn = new MySqlConnection(myConnection); MySqlCommand SelectCommand = new MySqlCommand(sql, myConn); MySqlCommand command = new MySqlCommand(sql, myConn); MySqlDataReader mdr; string selectQuery1 = ""; string insertQuery4 = ""; open_connections = 0; // open connection myConn.Open(); // command string selectQuery1 = "SHOW STATUS WHERE `variable_name` = 'Threads_connected'"; // execute commadnt to select quary SelectCommand = new MySqlCommand(selectQuery1, myConn); // assign varaible to reader of fethcing quary mdr = SelectCommand.ExecuteReader(); // assign value feteched to text box if (mdr.Read()) { open_connections = Int32.Parse(mdr.GetString("value")); } // close connection myConn.Close(); int total_rows = 0; if (open_connections > 30) { // open connection myConn.Open(); // command string selectQuery1 = "SELECT COUNT(*) FROM information_schema.processlist WHERE command = 'Sleep' and time>5"; // execute commadnt to select quary SelectCommand = new MySqlCommand(selectQuery1, myConn); // assign varaible to reader of fethcing quary mdr = SelectCommand.ExecuteReader(); // assign value feteched to text box if (mdr.Read()) { total_rows = Int32.Parse(mdr.GetString("COUNT(*)")); } // close connection myConn.Close(); List for (ii = 0; ii < total_rows; ii++) { // open connection myConn.Open(); selectQuery1 = "SELECT id FROM information_schema.processlist WHERE command = 'Sleep' and time>5 limit " + ii + ",1"; // execute commadnt to select quary SelectCommand = new MySqlCommand(selectQuery1, myConn); // assign varaible to reader of fethcing quary mdr = SelectCommand.ExecuteReader(); // assign value feteched to text box if (mdr.Read()) { ids_list.Add(mdr.GetString("id")); } // close connection myConn.Close(); } for (ii = 0; ii < ids_list.Count; ii++) { insertQuery4 = "kill " + ids_list[ii]; // open ocnnection myConn.Open(); command = new MySqlCommand(insertQuery4, myConn); if (command.ExecuteNonQuery() == 1) { } else { } // close connection myConn.Close(); } } | |
string strings = "red,blue,green"; List MessageBox.Show(string.Join(Environment.NewLine, test_list_2)); | |
public static class StringDistance { /// /// Compute the distance between two strings. /// public static int LevenshteinDistance(string s, string t) { int n = s.Length; int m = t.Length; int[,] d = new int[n + 1, m + 1]; // Step 1 if (n == 0) { return m; } if (m == 0) { return n; } // Step 2 for (int i = 0; i <= n; d[i, 0] = i++) { } for (int j = 0; j <= m; d[0, j] = j++) { } // Step 3 for (int i = 1; i <= n; i++) { //Step 4 for (int j = 1; j <= m; j++) { // Step 5 int cost = (t[j - 1] == s[i - 1]) ? 0 : 1; // Step 6 d[i, j] = Math.Min( Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + cost); } } // Step 7 return d[n, m]; } } private void button4_Click(object sender, EventArgs e) { MessageBox.Show((StringDistance.LevenshteinDistance("climax", "volmax")).ToString()); // MessageBox.Show(string.Join(Environment.NewLine, numbers)); } | |
// declae counter int i = 0; // store to filter in arrray string[] array1 = Directory.GetFiles(@"C:Usersmr bigDropbox2files manipulation work folderscopying1"); // outer loop go thorugh to filter foreach (string name in array1) { var filename1 = Path.GetFileNameWithoutExtension(array1[i]); var lastModified = System.IO.File.GetLastWriteTime(array1[i]); DateTime dateTime = DateTime.UtcNow.Date; DateTime file_change = Convert.ToDateTime(lastModified.ToString("MM/dd/yy")); TimeSpan difference = dateTime - file_change; string days_till = (difference.Days).ToString(); if (Int32.Parse(days_till)<=Int32.Parse(days_passed_box.Text)) { System.IO.File.Copy(array1[i], @"C:Usersmr bigDropbox2files manipulation work folderscopyingoutput 1" + filename1 + ".png"); } i = i + 1; } | |
string source = "1_2_3_4_5"; int count = source.Split('_').Length - 1; MessageBox.Show(count.ToString()); | |
string myConnection = "datasource=localhost;port=3306;username=root;password=''"; // conncet by varaible MySqlConnection myConn = new MySqlConnection(myConnection); // assign varaible to reading from data base MySqlDataReader mdr; string selectQuery1 = ""; MySqlCommand SelectCommand = new MySqlCommand(selectQuery1, myConn); int total_columns = 0; int ii = 0; List myConn.Open(); try { selectQuery1 = "SELECT COUNT(*) AS total_columns FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'methods' AND table_name = 'all_methods'; "; SelectCommand = new MySqlCommand(selectQuery1, myConn); mdr = SelectCommand.ExecuteReader(); if (mdr.Read()) { total_columns = Int32.Parse(mdr.GetString("total_columns")); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { myConn.Close(); } for (ii = 0; ii < total_columns; ii++) { myConn.Open(); try { selectQuery1 = "SELECT COLUMN_NAME FROM information_schema.columns WHERE TABLE_SCHEMA = 'tasks' AND TABLE_NAME = 'all_tasks' AND ORDINAL_POSITION = "+ii; SelectCommand = new MySqlCommand(selectQuery1, myConn); mdr = SelectCommand.ExecuteReader(); if (mdr.Read()) { columns_list.Add(mdr.GetString("COLUMN_NAME")); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { myConn.Close(); } } | |
List MessageBox.Show(Queryable.Average(list.AsQueryable()).ToString()); | |
string mystring = "12345"; String result = mystring.Substring(mystring.Length - 4); | |
string sMonth = DateTime.Now.ToString("MM"); MessageBox.Show(sMonth); | |
string current_month_as_number = DateTime.Now.ToString("MM"); | |
string currentYear = DateTime.Now.Year.ToString(); | |
DateTime datetime = DateTime.Now; ; MessageBox.Show((datetime.DayOfWeek).ToString()); | |
DateTime dateTime = Convert.ToDateTime("08/21/2021"); MessageBox.Show((dateTime.DayOfWeek).ToString()); | |
DateTime datetime = DateTime.Now; ; string month_number = DateTime.Now.ToString("MM"); int year_number = datetime.Year; int days = DateTime.DaysInMonth(year_number, Int32.Parse(month_number)); | |
room_name_box.Text =Path.GetFileName(assigned_image_box.Text); | |
string[] images_array = Directory.GetFiles(@"C:Usersmr bigDropboxcodec sharp one snippetsstyleimages"); string result = Path.GetFileNameWithoutExtension(images_array[0]); MessageBox.Show(result); | |
string input = "abc123def456"; string pattern = @"\d+"; Match match = Regex.Match(input, pattern); if (match.Success) { MessageBox.Show(match.Value); Console.WriteLine("First number found: {0}", match.Value); } else { } | |
public static string get_highest_numerical_suffix_function(string folder_path,string prefix_2) { string returned_value = ""; string prefix = prefix_2; string directoryPath = folder_path; int maxSuffix = 0; foreach (string filePath in Directory.GetFiles(directoryPath, prefix + " *")) { string fileName = Path.GetFileNameWithoutExtension(filePath); Match match = Regex.Match(fileName, prefix + " ([0-9]+)"); if (match.Success) { int suffix = int.Parse(match.Groups[1].Value); maxSuffix = Math.Max(maxSuffix, suffix); } } returned_value = maxSuffix.ToString(); return returned_value; } | |
int[] array = { 5, 6, 7, 6 }; int index1 = Array.FindIndex(array, item => item == 7); MessageBox.Show(index1.ToString()); | |
string mystring = "aaa_12345"; MessageBox.Show(mystring.Split('_').Last()); | |
List list_1.Add(5); list_1.Add(9); list_1.Add(2); MessageBox.Show(list_1.Max().ToString()); | |
DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25); TimeSpan ts = date2 - date1; Console.WriteLine("No. of Minutes (Difference) = {0}", ts.TotalMinutes); | |
DateTime date_time = DateTime.Now; int current_day = date_time.Day; int current_month = Int32.Parse(DateTime.Now.ToString("MM")); int current_year = Int32.Parse(DateTime.Now.Year.ToString()); string next_date_4 = ""; if (current_month != 12) { if (current_day < 10) { next_date_4 = current_month.ToString() + "/10/" + current_year.ToString(); } if (current_day >= 10) { next_date_4 = (current_month + 1).ToString() + "/10/" + current_year.ToString(); } } if (current_month == 12) { if (current_day < 10) { next_date_4 = current_month.ToString() + "/10/" + (current_year + 1).ToString(); } if (current_day >= 10) { next_date_4 = (current_month + 1).ToString() + "/10/" + (current_year + 1).ToString(); } } MessageBox.Show(next_date_4); | |
string date = "11/10/2022"; MessageBox.Show(date.Split('/')[0]); MessageBox.Show(date.Split('/')[1]); MessageBox.Show(date.Split('/')[2]); | |
MessageBox.Show(grid_1.Columns["date"].Index.ToString()); | |
string first_Word = "this is a string".Split(new char[] { single quote single quote })[0]; | |
var today = DateTime.Today; var yesterday = today.AddDays(-1); string yesterday_2 = yesterday.ToString("M/d/yyyy"); MessageBox.Show(yesterday_2); | |
public static string get_last_instance_of_day_in_next_month_function(int day_to_get) { string returned_date = ""; DateTime now = DateTime.Now; int next_month_year = now.Year; int next_month = now.Month + 1; if (now.Month == 12) { next_month = 1; next_month_year= next_month_year + 1; } int ii = 0; int instance_of_day_in_month = 0; int total_days_in_next_month = System.DateTime.DaysInMonth(next_month_year, next_month); for (ii = 1; ii <= total_days_in_next_month; ii++) { string date = next_month + "/" + ii + "/" + next_month_year; DateTime date_date_time = Convert.ToDateTime(date); int date_time_day = ((int)date_date_time.DayOfWeek == 0) ? 7 : (int)date_date_time.DayOfWeek; if (date_time_day == day_to_get-1) { returned_date = next_month + "/" + ii + "/" + next_month_year; } } return returned_date; } | |
char letter = 'a'; letter ++; | |
MessageBox.Show(DateTime.Now.Day.ToString()); | |
public static int minutes_difference_since_time_function(int hour, int minute) { DateTime now = DateTime.Now; int minutes_differnce = 0; int subtracted_day = now.Day; if (hour == now.Hour) { if (minute > now.Minute) { subtracted_day = DateTime.Today.AddDays(-1).Day; } } if (hour > now.Hour) { subtracted_day = DateTime.Today.AddDays(-1).Day; } DateTime date1 = new DateTime(now.Year, now.Month, subtracted_day, hour, minute, 0); DateTime date2 = new DateTime(now.Year, now.Month, now.Day,now.Hour, now.Minute, 0); TimeSpan ts = date2 - date1; minutes_differnce = Convert.ToInt32(ts.TotalMinutes); return minutes_differnce; } | |
DataGridViewRow row = this.grid_1.Rows[e.RowIndex]; string cell = row.Cells[e.ColumnIndex].Value.ToString(); string column = grid_1.Columns[e.ColumnIndex].HeaderText; if (column=="start_date") { try { DateTime dateTime = DateTime.UtcNow.Date; DateTime next_date_2 = DateTime.Parse(cell + " 12:00:00 AM"); TimeSpan difference = next_date_2 - dateTime; if (difference.Days < 999999) { MessageBox.Show("is date"); } } catch { } } | |
// connect string sql = " SELECT * FROM personal_website.previously_seen_movies"; string myConnection = "datasource=localhost;port=3306;username=root;password=''"; MySqlConnection myConn = new MySqlConnection(myConnection); MySqlCommand SelectCommand = new MySqlCommand(sql, myConn); MySqlDataReader mdr; string insertQuery4 = ""; int total_rows = 0; int ii = 0; total_rows = 0; string selectQuery1 = ""; // open connection myConn.Open(); // command string MySqlCommand command = new MySqlCommand(selectQuery1, myConn); // execute commadnt to select quary selectQuery1 = "SELECT count(*) FROM methods.all_methods"; // execute commadnt to select quary SelectCommand = new MySqlCommand(selectQuery1, myConn); // assign varaible to reader of fethcing quary mdr = SelectCommand.ExecuteReader(); // assign value feteched to text box if (mdr.Read()) { total_rows= Int32.Parse(mdr.GetString("count(*)")); } // close connection myConn.Close(); List List for (ii = 1; ii <= total_rows; ii++) { // open connection myConn.Open(); // command string selectQuery1 = "SELECT table_name FROM methods.all_methods where level>2 and id ="+ii; // execute commadnt to select quary SelectCommand = new MySqlCommand(selectQuery1, myConn); // assign varaible to reader of fethcing quary mdr = SelectCommand.ExecuteReader(); // assign value feteched to text box if (mdr.Read()) { bool alreadyExist = above_l3_systems.Contains(mdr.GetString("table_name")); if (alreadyExist == true) { } else { above_l3_systems.Add(mdr.GetString("table_name")); } } // close connection myConn.Close(); } // get all culomns in table // populate columns // ./. int total_columns = 0; // open connection myConn.Open(); // command string selectQuery1 = "SELECT COUNT(*) AS total_columns FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'graphs' AND table_name = 'l3_and_above_medals_in_systems'; "; // execute commadnt to select quary SelectCommand = new MySqlCommand(selectQuery1, myConn); // assign varaible to reader of fethcing quary mdr = SelectCommand.ExecuteReader(); // assign value feteched to text box if (mdr.Read()) { total_columns = Int32.Parse(mdr.GetString("total_columns")); } // close connection myConn.Close(); for (ii = 1; ii <= total_columns; ii++) { // open connection myConn.Open(); // command string selectQuery1 = " SELECT COLUMN_NAME FROM information_schema.columns WHERE TABLE_SCHEMA = 'graphs' AND TABLE_NAME = 'l3_and_above_medals_in_systems' AND ORDINAL_POSITION = " + ii; // execute commadnt to select quary SelectCommand = new MySqlCommand(selectQuery1, myConn); // assign varaible to reader of fethcing quary mdr = SelectCommand.ExecuteReader(); // assign value feteched to text box if (mdr.Read()) { if (mdr.GetString("COLUMN_NAME") != "id") { bool alreadyExist = above_l3_systems.Contains(mdr.GetString("COLUMN_NAME")); if (alreadyExist == true) { } else { if (mdr.GetString("COLUMN_NAME") != "xxx" && mdr.GetString("COLUMN_NAME") != "all_methods") { all_systems.Add(mdr.GetString("COLUMN_NAME")); } } } } // close connection myConn.Close(); } for (ii = 0; ii < above_l3_systems.Count; ii++) { all_systems.Add(above_l3_systems[ii]); } all_systems.Sort(); for (ii = 0; ii < above_l3_systems.Count; ii++) { insertQuery4 = "ALTER TABLE graphs.l3_and_above_medals_in_systems ADD COLUMN " + above_l3_systems[ii] + " int DEFAULT 0"; // open ocnnection myConn.Open(); try { command = new MySqlCommand(insertQuery4, myConn); if (command.ExecuteNonQuery() == 1) { } else { } // close connection } catch { } myConn.Close(); } for (ii = 0; ii < all_systems.Count; ii++) { if (ii == 0) { insertQuery4 = "ALTER TABLE graphs.l3_and_above_medals_in_systems MODIFY COLUMN " + all_systems[ii] + " int AFTER id"; } else{ insertQuery4 = "ALTER TABLE graphs.l3_and_above_medals_in_systems MODIFY COLUMN " + all_systems[ii] + " int AFTER "+ all_systems[ii-1]+";"; } // open ocnnection myConn.Open(); command = new MySqlCommand(insertQuery4, myConn); if (command.ExecuteNonQuery() == 1) { } else { } // close connection myConn.Close(); } | |
if (Path.GetFileNameWithoutExtension(images_array[ii]).StartsWith(search_box.Text)) { dropdown_1.Items.Add(new KeyValuePair dropdown_2.Items.Add(new KeyValuePair } | |
string str = "_5_moves"; Regex regex = new Regex(@"\d+"); // Match one or more digits in the string Match match = regex.Match(str); if (match.Success) { int number = int.Parse(match.Value); number -= 2; str = regex.Replace(str, number.ToString(), 1); // Replace the first occurrence of the number in the string } MessageBox.Show(str); | |
string originalString = "This is a sample string"; string wordToFind = "sample"; int index = originalString.IndexOf(wordToFind); if (index != -1) { string modifiedString = originalString.Substring(0, index + wordToFind.Length); Console.WriteLine(modifiedString); } | |
detail_box_1.Text = detail_box_1.Text.Trim(new Char[] { 'x', 'y', 'z' }); | |
MessageBox.Show(string.Concat("hello".Reverse().Skip(3).Reverse())); | |
MessageBox.Show(string.Concat("hello".Skip(3))); | |
detail_box_1.Text = detail_box_1.Text.Replace(""", ""); | |
List List list1 = list1.Except(list2).ToList(); | |
list_1.RemoveAt(list_1.Count - 1) | |
int jj = 0; List labels.Add(1); labels.Add(2); labels.Add(3); labels.Add(5); labels.Add(8); labels.Add(16); List List int differnce_between_labels = 0; while (labels.Count >4) { differnce_between_labels_list.Clear(); for (jj = 1; jj < labels.Count; jj++) { differnce_between_labels = labels[jj] - labels[jj - 1]; bool alreadyExist = differnce_between_labels_list.Contains(differnce_between_labels); if (alreadyExist == true) { } else { differnce_between_labels_list.Add(differnce_between_labels); } } // loop labels if min differnce remove item for (jj = 1; jj < labels.Count; jj++) { differnce_between_labels = labels[jj] - labels[jj - 1]; if (differnce_between_labels == differnce_between_labels_list.Min()) { labels.Remove(labels[jj]); jj = labels.Count; } } } MessageBox.Show(string.Join(Environment.NewLine, labels)); | |
List string itemToRemove = "Foo"; if(myList.Contains(itemToRemove)){ myList.Remove(itemToRemove); } | |
string last_room = "0_1_2_3"; int trimPosition; if ((trimPosition = last_room.LastIndexOf('_')) > -1) last_room = last_room.Substring(0, trimPosition); MessageBox.Show(last_room); | |
returned_paragraph = Regex.Replace(paragraph, @"\r\n?|\n", " "); | |
string phrase = "The quick brown fox jumps over the lazy dog."; string[] words = phrase.Split(' '); List foreach (var word in words) { numbers.Add(word); } MessageBox.Show(string.Join(Environment.NewLine, numbers)); | |
List List List List list_1.Add(2); list_1.Add(3); list_1.Add(1); list_2.Add("b"); list_2.Add("c"); list_2.Add("a"); int ii = 0; while(ii< list_1.Count) { if (list_1[ii]== list_1.Max()) { list_1_sorted.Add(list_1[ii]); list_2_sorted.Add(list_2[ii]); list_1.RemoveAt(ii); list_2.RemoveAt(ii); ii = -1; } ii = ii + 1; } MessageBox.Show(string.Join(Environment.NewLine, list_1_sorted)); MessageBox.Show(string.Join(Environment.NewLine, list_2_sorted)); | |
var split = today_box.Text.Split('/'); if (split[0].Length == 1|| split[1].Length == 1) { MessageBox.Show("add zero before day and month"); } | |
if (images_array[ii].Equals(Path.GetFileNameWithoutExtension(images_array[ii]), StringComparison.InvariantCultureIgnoreCase)) {} | |
// connect to data base string sql = " SELECT * FROM counts "; string myConnection = "datasource=localhost;port=3306;username=root;password='';Charset=utf8"; MySqlConnection myConn = new MySqlConnection(myConnection); MySqlCommand SelectCommand = new MySqlCommand(sql, myConn); // assign varaible to reading from data base string insertQuery4 = ""; MySqlCommand command = new MySqlCommand(insertQuery4, myConn); insertQuery4 = "update misc_storages.inner_world_picture_assignment set picture = '"+ MySql.Data.MySqlClient.MySqlHelper.EscapeString(assigned_image_box.Text) + "' where room='level_0'"; // open ocnnection myConn.Open(); command = new MySqlCommand(insertQuery4, myConn); if (command.ExecuteNonQuery() == 1) { } else { MessageBox.Show("Data Not Inserted"); } // close connection myConn.Close(); | |
string title_column_value = row.Cells[grid_1.Columns["title"].Index].Value.ToString(); | |
xxx |